using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.Threading;
using System.Diagnostics;


namespace Utilities.Menu
{
    public enum FadeType
    {
        In,
        Out
    }

    public class Fader : GameComponent
    {
        float alpha, min_value, max_value;
        FadeType fade_type;

        public Fader(Game game, FadeType fade_type, float alpha, float min_value, float max_value)
            : base(game)
        {
            this.alpha = alpha;
            this.min_value = min_value;
            this.max_value = max_value;

            this.fade_type = fade_type;
        }

        public override void Update(GameTime gameTime)
        {
            var dt = (float)gameTime.ElapsedGameTime.TotalSeconds * 2.0f;

            alpha = fade_type == Menu.FadeType.In ? MathHelper.Clamp(alpha + dt, 0, 1) : MathHelper.Clamp(alpha - dt, 0, 1);
            
            base.Update(gameTime);
        }

        public float Alpha
        {
            get { return alpha; }
        }

        public FadeType FadeType
        {
            get { return fade_type; }
            set { fade_type = value; }
        }
    }
}
